package com.ndp.fb.rdb.db.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ndp.fb.rdb.api.AdTitleHistoryRdbServices;
import com.ndp.fb.rdb.db.DaoTemplate;
import com.ndp.fb.rdb.db.impl.mapper.DefaultRowMapper;
import com.ndp.fb.rdb.model.AdTitleHistory;

import java.util.List;

/**
 * Created by infi on 2015/1/31.
 */
@Service
public class AdTitleHistoryRdbServicesImpl extends DaoTemplate implements AdTitleHistoryRdbServices {

    @Override
    public List<AdTitleHistory> findByCreatorIdAndConnectionObjectId(Long creatorId, Long connectionObjectId) {
        String sql = "SELECT * FROM `ad_title_history` WHERE creator_id =? AND connection_object_id =? ORDER BY id DESC limit 10";
        return getJdbcTemplate().query(sql, new Object[]{creatorId, connectionObjectId}, DefaultRowMapper.autoRowMapper(AdTitleHistory.class));
    }

    @Override
    public AdTitleHistory isExistedAdTitleHistory(Long creatorId, Long connectionObjectId, String title) {
        String sql = "SELECT * FROM `ad_title_history` WHERE creator_id =? AND connection_object_id =? AND title =?";
        return findOne(sql, new Object[]{creatorId, connectionObjectId, title}, DefaultRowMapper.autoRowMapper(AdTitleHistory.class));
    }

    @Override
    public Long saveAdTitleHistory(final AdTitleHistory obj) {
        return saveResultId(obj);
    }
}
